package com.yenlien.traceyun.breed.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.breed.entity.Feed;
import com.yenlien.traceyun.breed.service.FeedService;
import com.yenlien.traceyun.business.interceptor.DataAuth;
import com.yenlien.traceyun.webase.controller.BaseController;

/**
 * 喂养控制层
 *
 * @author maybe
 * @date 2020年9月23日
 */
@RestController
@RequestMapping("/feed")
public class FeedController extends BaseController {
    @Autowired
    private FeedService feedService;

    //分页查询列表
    @DataAuth
    @RequestMapping(value = "/findByList", method = RequestMethod.POST)
    public Object findByList(@RequestBody JSONObject params) {
        Feed feed = new Feed();
        feed.setPrincipalName(params.getString("searchName"));
        feed.setPage(params.getIntValue("page"));
        feed.setPageSize(params.getIntValue("pageSize"));
        feed.setBreedId(params.getString("breedId"));
        return buildPage(feedService.findByList(feed));
    }

    //新增
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Object save(@RequestBody Feed feed) {
        feedService.save(feed);
        return success("success");
    }
}
